package me.jessyan.mvparms.demo.mvp.ui.activity.integral;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.example.xrecyclerview.XRecyclerView;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.widget.CustomPopupWindow;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.di.component.integral.DaggerMineScoreComponent;
import me.jessyan.mvparms.demo.di.module.integral.MineScoreModule;
import me.jessyan.mvparms.demo.mvp.contract.integral.MineScoreContract;
import me.jessyan.mvparms.demo.mvp.presenter.integral.MineScorePresenter;
import me.jessyan.mvparms.demo.mvp.ui.adapter.MyIntegralRecordAdapter;
import me.jessyan.mvparms.demo.mvp.ui.widget.CustomToolbar;
import me.jessyan.mvparms.demo.utils.PerfectClickListener;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * 我的积分页面
 */
public class MineScoreActivity extends BaseActivity<MineScorePresenter> implements MineScoreContract.View ,CustomPopupWindow.CustomPopupWindowListener{

    @BindView(R.id.toolbar)
    CustomToolbar toolbar;
    @BindView(R.id.choice_tv)
    TextView choiceTv;
    @BindView(R.id.recyclerView)
    XRecyclerView recyclerView;

    @Inject
    CustomPopupWindow choicePop;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerMineScoreComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .mineScoreModule(new MineScoreModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_mine_score; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        toolbar.setListener(new CustomToolbar.ToolbarListener() {
            @Override
            public void onLeftBack() {
                killMyself();
            }

            @Override
            public void onRightBack() {

            }
        });
        choiceTv.setOnClickListener(new PerfectClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                choicePop.showAsDropDown(choiceTv);

            }
        });


        initRecycler();

    }

    private void initRecycler() {
        List<Boolean> list = new ArrayList<>();
        int i= 0;
        while (i<10){


        list.add(true);
        list.add(false);
        list.add(false);
        list.add(false);

        list.add(true);
        list.add(false);

        list.add(true);
        list.add(false);
        list.add(false);

        list.add(true);
        list.add(false);
        i++;
        }

    recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext(),LinearLayoutManager.VERTICAL,false));
    recyclerView.setAdapter(new MyIntegralRecordAdapter(list));

     recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
         @Override
         public void onRefresh() {

         }

         @Override
         public void onLoadMore() {

         }
     });
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @Override
    public MineScoreActivity getActivity() {
        return this;
    }




    @Override
    public void initPopupView(View contentView) {
            contentView.findViewById(R.id.all_tv).setOnClickListener(new PerfectClickListener() {
                @Override
                protected void onNoDoubleClick(View v) {
                    choiceTv.setText("全部");
                    choicePop.dismiss();
                }
            });
            contentView.findViewById(R.id.gain_tv).setOnClickListener(new PerfectClickListener() {
                @Override
                protected void onNoDoubleClick(View v) {
                    choiceTv.setText("获取");
                    choicePop.dismiss();
                }
            });
            contentView.findViewById(R.id.use_tv).setOnClickListener(new PerfectClickListener() {
                @Override
                protected void onNoDoubleClick(View v) {
                    choiceTv.setText("使用");
                    choicePop.dismiss();
                }
            });
    }
}
